namespace SinaFinance.ChartLibrary.AxisLibrary
{
    using SinaFinance;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Shapes;

    public partial class Legend : UserControl
    {
        //private bool _contentLoaded;
        //internal Grid LayoutRoot;
        private Rectangle rctFstStock;
        private Rectangle rctScdStock;
        //internal Canvas rootCanvas;
        private TextBlock txtFstStkCode;
        private TextBlock txtScdStockCode;

        public Legend()
        {
            this.InitializeComponent();
        }

        public Legend(Color FstColor, string FstCode, Color ScdColor, string ScdCode)
        {
            this.InitializeComponent();
            string str = this.InitStockName(FstCode);
            string str2 = this.InitStockName(ScdCode);
            this.rctFstStock = new Rectangle();
            this.rctFstStock.Width = 25.0;
            this.rctFstStock.Height = 5.0;
            this.rctFstStock.Margin = new Thickness(5.0, 5.0, 0.0, 0.0);
            this.rctFstStock.Fill = new SolidColorBrush(FstColor);
            this.txtFstStkCode = new TextBlock();
            this.txtFstStkCode.Margin = new Thickness(this.rctFstStock.Width + 10.0, 0.0, 0.0, 0.0);
            this.txtFstStkCode.Foreground = new SolidColorBrush(FstColor);
            this.txtFstStkCode.Text = FstCode + " " + str;
            this.rctScdStock = new Rectangle();
            this.rctScdStock.Width = 25.0;
            this.rctScdStock.Height = 5.0;
            this.rctScdStock.Margin = new Thickness((this.txtFstStkCode.ActualWidth + this.txtFstStkCode.Margin.Left) + 10.0, 5.0, 0.0, 0.0);
            this.rctScdStock.Fill = new SolidColorBrush(ScdColor);
            this.txtScdStockCode = new TextBlock();
            this.txtScdStockCode.Margin = new Thickness((this.rctScdStock.Width + this.rctScdStock.Margin.Left) + 10.0, 0.0, 0.0, 0.0);
            this.txtScdStockCode.Foreground = new SolidColorBrush(ScdColor);
            this.txtScdStockCode.Text = ScdCode + " " + str2;
            base.Width = this.txtScdStockCode.Margin.Left + this.txtScdStockCode.ActualWidth;
            this.rootCanvas.Children.Add(this.rctFstStock);
            this.rootCanvas.Children.Add(this.txtFstStkCode);
            this.rootCanvas.Children.Add(this.rctScdStock);
            this.rootCanvas.Children.Add(this.txtScdStockCode);
        }

        //[DebuggerNonUserCode]
        //public void InitializeComponent()
        //{
        //    if (!this._contentLoaded)
        //    {
        //        this._contentLoaded = true;
        //        Application.LoadComponent(this, new Uri("/SinaFinance;component/ChartLibrary/AxisLibrary/Legend.xaml", UriKind.Relative));
        //        this.LayoutRoot = (Grid) base.FindName("LayoutRoot");
        //        this.rootCanvas = (Canvas) base.FindName("rootCanvas");
        //    }
        //}

        private string InitStockName(string stockID)
        {
            string cookie = CookieControl.GetCookie("cookie_history");
            List<string> list = null;
            if (!string.IsNullOrEmpty(cookie))
            {
                int num;
                list = cookie.Split(new char[] { '$' }).ToList<string>();
                for (num = list.Count - 1; num > -1; num--)
                {
                    if (list[num].Trim().Equals(string.Empty))
                    {
                        list.RemoveAt(num);
                    }
                }
                for (num = list.Count - 1; num > -1; num--)
                {
                    string[] strArray = list[num].Split(new char[] { '_' });
                    int length = strArray.Length;
                    if (length.Equals(3) && strArray[1].Equals(stockID))
                    {
                        return strArray[2];
                    }
                }
            }
            return string.Empty;
        }
    }
}
